
#!/usr/bin/python
import os
import sys
import time

suffix = ['linked.rbc','llvm.bc']
opts = ['nopt','abc','gvn','abcd']

inp = {'cjpeg':'testimg.ppm',
       'encode':'clinton.pcm',
       'mpeg2decode':'mei16v2.m2v',
       'rawcaudio':'clinton.pcm',
       'rawdaudio':'clinton.pcm',
       'toast':'clinton.pcm',
      }

def gen_cmd(bench, opt, suf):
    if opt != 'nopt':
        opt = '%s.' %opt
    else:
        opt = ''
    if bench == 'mpeg2decode':
        return 'lli %s/%s.%s%s -b %s/%s' %(bench, bench, opt, suf, bench, inp[bench])
    return 'lli %s/%s.%s%s < %s/%s > /dev/null' %(bench, bench, opt, suf, bench, inp[bench])

bench_name = sys.argv[1]

for s in suffix:
    for o in opts:
        cmd = gen_cmd(bench_name, o, s)
        print cmd
        sys.stdout.flush()
        start = time.time()
        os.system(cmd)
        end = time.time()
        print "Time Elapsed: %s sec" %(end - start)
        sys.stdout.flush()
